package bid.yanhj.ssm.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import bid.yanhj.ssm.po.User;

@Controller
public class LoginJsonController {

    private static final Logger LOG = LoggerFactory.getLogger(LoginJsonController.class);

    /**
     * 登录
     */
    @RequestMapping("/userLogin")
    @ResponseBody
    public Map<String, Object> login(HttpSession session, @RequestBody User user) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        LOG.debug("【接受前端报文");
        System.out.println(user.getUsername());
        if (user.getUsername() != null) {
            // 在session中保存用户身份信息
            session.setAttribute("username", user.getUsername());
            resultMap.put("msg", "操作成功");
            resultMap.put("status", 0);
        }

        return resultMap;
    }
}
